/**
 * 
 */
package spatial.geometry;

/**
 * @author wu wei
 * 
 */
public class LeveledIntersection extends Intersection implements
		Comparable<LeveledIntersection> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8515788750303563948L;
	int level;

	/**
	 * @param l1
	 * @param l2
	 */
	public LeveledIntersection(LineFunction l1, LineFunction l2) {
		super(l1, l2);
		this.level = 0;
	}

	/**
	 * @return the level
	 */
	public int getLevel() {
		return level;
	}

	/**
	 * @param level
	 *            the level to set
	 */
	public void setLevel(int level) {
		this.level = level;
	}

	public String toString() {
		String s = super.toString();
		s = s + ", level: " + this.level;
		return s;
	}

	public int compareTo(LeveledIntersection o) {
		/**
		 * compare based on x value first, then y value, then l1's value, then
		 * l2's value
		 */
		int xCompare = (new java.lang.Double(this.getX()))
				.compareTo(new java.lang.Double(o.getX()));
		if (xCompare == 0) {
			int yCompare = (new java.lang.Double(this.getY()))
					.compareTo(new java.lang.Double(o.getY()));
			if (yCompare == 0) {
				int l1Compare = new Integer(this.l1.getUniqueLineFunctionId())
						.compareTo(new Integer(o.l1.getUniqueLineFunctionId()));
				if (l1Compare == 0) {
					int l2Compare = new Integer(this.l2
							.getUniqueLineFunctionId()).compareTo(new Integer(
							o.l2.getUniqueLineFunctionId()));
					return l2Compare;
				} else {
					return l1Compare;
				}
			} else {
				return yCompare;
			}
		} else {
			return xCompare;
		}
	}

	public LeveledIntersection clone() {
		LeveledIntersection li = new LeveledIntersection(this.l1, this.l2);
		li.level = this.level;
		return li;
	}

}
